<?php
include_once("config.inc");
require_once("alexa_info.php");


function search($query,$start){
	$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
    	. "q=".$query."&key=".GOOGLE_KEY."&rsz=large&start=$start&userip=USERS-IP-ADDRESS";

	// sendRequest
	// note how referer is set manually
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_REFERER, 'www.zhaiziming.com/deepin/');
	$body = curl_exec($ch);
	curl_close($ch);

	// now, process the JSON string
	$json = json_decode($body,true);
	
	return $json['responseData']['results'];

}

function google_search($query){
	$array = search($query,0);
	$array1 = search($query,8);
	$array2 = search($query,16);
	$array3 = array_merge($array,$array1,$array2);

	return $array3;
}

?>